savasvikifandomcom_tr-20200215-history
Modül:Savaş bilgi kutusu
require('Modül:No globals') local infoboxStyle = mw.loadData('Modül:WPMILHIST Bilgi kutusu biçimi') local IMC = {} IMC.__index = IMC function IMC:renderPerCombatant(builder, headerText, prefix, suffix) prefix = prefix or '' suffix = suffix or '' local colspans = {} -- This may result in colspans1 getting set twice, but -- this is no big deal. The second set will be correct. local lastCombatant = 1 for i = 1,self.combatants do if self.args.. i .. suffix then colspanslastCombatant = i - lastCombatant lastCombatant = i end end local jointText = self.args.. (self.combatants + 1) .. suffix if headerText and (colspans1 or jointText) then builder:tag('tr') :tag('th') :attr('colspan', self.combatants) :cssText(infoboxStyle.header_raw) :wikitext(headerText) end -- The only time colspans1 wouldn't be set is if no -- combatant has a field with the given prefix and suffix. if colspans1 then -- Since each found argument set the colspan for the previous -- one, the final one wasn't set above, so set it now. colspanslastCombatant = self.combatants - lastCombatant + 1 builder = builder:tag('tr') for i = 1,self.combatants do -- At this point, colspansi will be set for i=1 unconditionally, and for -- any other value of i where self.args.. i .. suffix is set. if colspansi then builder:tag('td') -- don't bother emitting colspan="1" :attr('colspan', colspansi ~= 1 and colspansi or nil) :css('width', math.floor(100 / self.combatants * colspansi + 0.5) .. '%') -- no border on the right of the rightmost column :css('border-right', i ~= lastCombatant and infoboxStyle.internal_border or nil) -- no padding on the left of the leftmost column :css('padding-left', i ~= 1 and '0.25em' or nil) -- don't show the border if we're directly under a header :css('border-top', not headerText and infoboxStyle.internal_border or nil) :newline() :wikitext(self.args.. i .. suffix) end end end if jointText then builder:tag('tr') :tag('td') :attr('colspan', self.combatants) :css('text-align', 'center') -- don't show the border if we're directly under a header :css('border-top', (not headerText or colspans1) and infoboxStyle.internal_border or nil) :newline() :wikitext(jointText) end end function IMC:renderHeaderTable(builder) builder = builder:tag('table') :css('width', '100%') :css('margin', 0) :css('padding', 0) :css('border', 0) if self.args'tarih' then builder:tag('tr') :tag('th') :css('padding-right', '1em') :wikitext('Tarih') :done() :tag('td') :wikitext(self.args'tarih') end if self.args'bölge' or self.args'yer' then builder:tag('tr') :tag('th') :css('padding-right', '1em') :wikitext('Bölge') :done() :tag('td') :tag('span') :addClass('location') :wikitext((self.args'yer' or ) .. (self.args'yer' and self.args'bölge' and ', ' or '') .. (self.args'bölge' or '')) end if self.args'koordinatlar' then builder:wikitext(' ' .. self.args'koordinatlar') end if self.args'sebep' then builder:tag('tr') :tag('th') :css('padding-right', '1em') :wikitext(self.args'sebep' and 'Sebep') :done() :tag('td') :wikitext(self.args'sebep') end if self.args'durum' or self.args'sonuç' then builder:tag('tr') :tag('th') :css('padding-right', '1em') :wikitext(self.args'durum' and 'Durum' or 'Sonuç') :done() :tag('td') :wikitext(self.args'durum' or self.args'sonuç') end if self.args'coğrafi_değişiklikler' then builder:tag('tr') :tag('th') :css('padding-right', '1em') :wikitext('Coğrafi Değişiklikler') :done() :tag('td') :newline() :wikitext(self.args'coğrafi_değişiklikler') end end function IMC:render() local builder = mw.html.create() if self.args'cephekutusu' then builder = builder:tag('table') :css('float', 'right') :css('clear', 'right') :css('background', 'transparent') :css('margin', 0) :css('padding', 0) :tag('tr'):tag('td') end builder = builder:tag('table') :addClass('infobox vevent') :cssText(infoboxStyle.main_box_raw_auto_width) :css('width', self.args'genişlik' or '315px') builder:tag('tr') :tag('th') :addClass('summary') :attr('colspan', self.combatants) :cssText(infoboxStyle.header_raw) :wikitext(self.args'çatışma' or mw.title.getCurrentTitle().text) if self.args'parçası' then builder:tag('tr') :tag('td') :attr('colspan', self.combatants) :cssText(infoboxStyle.sub_header_raw) :wikitext(self.args'parçası') end if self.args'resim' then builder:tag('tr') :tag('td') :attr('colspan', self.combatants) :cssText(infoboxStyle.image_box_raw) :wikitext(string.format('%s%s%s', require('Modül:InfoboxImage').InfoboxImage{args = { image = self.args'resim', size = self.args'resim_boyutu', sizedefault = 'frameless', upright = 1, alt = self.args'resim_alt' }}, self.args'başlık' and ' ' or '', self.args'başlık' or '' )) end if self.args.harita then builder:tag('tr') :tag('td') :attr('colspan', self.combatants) :cssText(infoboxStyle.image_box_raw) :tag('center') :node(require('Module:Location map').main(self.frame, { self.args.harita, relief = self.args.map_relief, lat = self.args.latitude, long = self.args.longitude, width = self.args.harita_boyut or 220, float = 'center', border = 'none', mark = self.args.map_mark, marksize = self.args.map_marksize or 8, label = self.args.map_label, alt = self.args.map_alt, label = self.args.map_caption or ('Location within ' .. self.args.map_type) })) end self:renderHeaderTable(builder:tag('tr'):tag('td'):attr('colspan', self.combatants)) self:renderPerCombatant(builder, self.args'savaşanlar_başlık' or 'Taraflar', 'savaşan') -- can be un-hardcoded once gerrit:165108 is merged for _,v in ipairs{'a','b','c','d'} do self:renderPerCombatant(builder, nil, 'savaşan', v) end self:renderPerCombatant(builder, 'Komutanlar ve liderler', 'komutan') self:renderPerCombatant(builder, 'Çatışan birlikler', 'birlik') self:renderPerCombatant(builder, 'Güçler', 'güç') self:renderPerCombatant(builder, 'Siyasi destekler', 'siyasi_destek') self:renderPerCombatant(builder, 'Askeri destekler', 'askeri_destek') self:renderPerCombatant(builder, 'Kayıplar', 'kayıp') if self.args'notlar' then builder:tag('tr') :tag('td') :attr('colspan', self.combatants) :css('font-size', '90%') :css('border-top', infoboxStyle.section_border) :newline() :wikitext(self.args'notlar') end builder = builder:done() if self.args'cephekutusu' then builder = builder:done():done():tag('tr') :tag('td') :wikitext(self.args'cephekutusu') :done() :done() end return builder end function IMC.new(frame, args) if not args then args = require('Modül:Arguments').getArgs(frame, {wrappers = 'Şablon:Savaş bilgi kutusu'}) end local obj = { frame = frame, args = args } -- until gerrit:165108 is merged, there's still a cap on combatants, but as soon as it merges, we can update this little bit of code to uncap it -- also, don't try to make this more efficient, or references could be in the wrong order obj.combatants = 2 for _,v in ipairs{, 'a', 'b', 'c', 'd'} do for i = 1,5 do if args.. i .. v then obj.combatants = math.max(obj.combatants, i) end end end return setmetatable(obj, IMC) end local p = {} function p.main(frame) return IMC.new(frame):render() end return p